<template>
    <div id="bus_flow">
        <el-form :inline="true" size="medium">
			<el-form-item>
				<el-select v-model="params.type" placeholder="流水类型" clearable @change="search">
					<el-option value="1" label="入账"></el-option>
					<el-option value="2" label="支出"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="params.bus_id" placeholder="商家ID"></el-input>
			</el-form-item>
            <el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
			</el-form-item>
		</el-form>

        <el-table :data="list" stripe v-loading="loading">
            <el-table-column align="center" label="流水类型">
                <template slot-scope="scope">
                    <span v-if="scope.row.type == 1">入账</span>
                    <span v-if="scope.row.type == 2">支出</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="商户ID" prop="bus_id"></el-table-column>
            <el-table-column align="center" label="金额">
                <template slot-scope="scope">
                    <span>{{scope.row.type == 1?'+':'-'}}{{scope.row.amount}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="备注" prop="deal_desc"></el-table-column>
            <el-table-column align="center" label="创建时间">
                <template slot-scope="scope">
                    {{$common.getDate(scope.row.create_time)}}
                </template>
            </el-table-column>
        </el-table>

        <el-pagination 
            background 
            @size-change="handleSizeChange" 
            @current-change="getList" 
            :current-page.sync="params.pageNo"
		    :page-sizes="[10, 20, 50, 100]" 
            :page-size="params.pageSize" 
            layout="total, sizes, prev, pager, next, jumper" 
            :total="total">
		</el-pagination>
    </div>
</template>

<script>
export default {
    name: '',
    data() {
        return {
            params: {
                type: '',
                isCount: true,
                busId: '',
                startTime: '',
                endTime: '',
                pageNo: 1,
                pageSize: 10,
                tenantid:sessionStorage.getItem("tenantid")
            },
            timeArr: [],
            list: [],
            loading: false,
            total: 100
        }
    },
    created(){
        this.getList()
    },
    mounted(){},
    watch: {},
    methods: {
        handleSizeChange(e){
            this.params.isCount = true
            this.params.pageSize = e
            this.getList()
        },
        search(){
            this.params.isCount = true
            this.getList()
        },
        getList(){
            this.loading = true
            this.$request.post({
                url:'/ReportApi/tenant/userflowList',
                params: this.params,
                success: res => {
                    this.list = res[0]
                    if (this.params.isCount) {
                        this.params.isCount = false
                        this.total = res[1]
                    }
                },
                finally: res => {
                    this.loading = false
                }
            })
        },
        timeChange(val){
            if(val){
                this.params.startTime = this.$common.getDate(val[0]);
                this.params.endTime = this.$common.getDate(val[1]);
            }else{
                this.params.startTime = ''
                this.params.endTime = ''
            }
        },
    }
}
</script>

<style lang="scss" scoped>
#bus_flow{
    .el-pagination{
        text-align: right;
        padding-top: 20px;
    }
}
</style>